package org.hackystat.sdsa.analyzer.control.tokenizer;

import java.util.List;

import org.hackystat.sdsa.analyzer.model.activity.Activity;
import org.hackystat.sdsa.analyzer.model.activity.BufferTransActivity;

/**
 * Implements the buffer transition tokenizer to divide a development stream into buffer
 * transition episodes.
 * 
 * @author hongbing
 */
public class BufferTransTokenizer extends Tokenizer {
  /**
   * Looks ahead for next buffer trans.
   * 
   * @param activityList List of activities in a development stream.
   * @param start Next episode start.
   * @return Next buffer trans token.
   */
  @Override public int lookAhead(List<Activity> activityList, int start) {
    int cursor = -1;    
    for (cursor = start; cursor < activityList.size(); cursor++) {
      Activity activity = activityList.get(cursor);
      if (activity instanceof BufferTransActivity) {
        break;
      }
    }
    
    if (cursor < activityList.size()) {
      return cursor;  
    }
    else {
      return activityList.size() - 1;
    }
  }
}
